<template>
	<view class="base-content">
		<!-- <page-head>
			<slot slot="title">{{title.length>10?title.substr(0,10)+'...':title}}</slot>
			<slot slot="right">{{''}}</slot>
		</page-head> -->
		<yk-header :title="title" @headBtn="headBtn()" @closePage="closePage()"></yk-header>
		<view class="base-box" v-if="userRank>0&&userRank!=''">
			<view>发卡数</view>
			<view class="base-box-number">{{sendCardnumber}}<text>张</text></view>
		</view>
		<view class="base-box">
			<view>绑定卡数</view>
			<view class="base-box-number">{{bindCardnumber}}<text>张</text></view>
		</view>
		<view class="base-box">
			<view>已激活卡数</view>
			<view class="base-box-number">{{readyactCard}}<text>张</text></view>
		</view>
		<view class="base-box">
			<view>未激活卡数</view>
			<view class="base-box-number">{{notactCard}}<text>张</text></view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(event) {
			if(event.userRank){
				this.userRank=event.userRank;
			}
			console.log(this.userRank);
			this.getBase();
		},
		onShow() {
			
		},
		data() {
			return {
				sendCardnumber:0,
				bindCardnumber:0,
				readyactCard:0,
				userRank:'',
				notactCard:0,
				loadingText: '加载中...',
				title:'基本统计'
			};
		},
		onReachBottom: function() {
		},
		onPullDownRefresh: function() {
			this.getBase();
		},
		methods: {
			//顶部功能键
			headBtn(e){
				let that=this;
				uni.showActionSheet({
					itemList: ['刷新', '清除缓存'],
					success: function (res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if(res.tapIndex==0){
							//刷新
							that.getBase();
						}else{
							//清楚缓存
							// callNative('onClearH5Cache')
							uni.showToast({
								title: '清除缓存成功'
							});
						}
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
			//关闭当前页面
			closePage(){
				callNative('navigateBack') 
			},
			getBase() {
				try {
					uni.request({
						url: this.$usereq + '/coupon-expand/promote/bind/basic/statistics',
						method: 'GET',
						header: {
							'blade-auth': decodeURI(uni.getStorageSync('token')),
							'content-type': 'application/json'
						},
						data: {},
						success: res => {
							let datas = res.data;
							console.log(datas);
							if(datas.code==200){
								this.sendCardnumber = datas.data.card_total;
								this.bindCardnumber = res.data.data.cou_total;
								this.readyactCard = res.data.data.cou_jh;
								this.notactCard = res.data.data.cou_wjh;
								// console.log(this.sendCardnumber);
							}else{
								uni.showToast({
									title: datas.msg,
									icon:'none',
									duration: 2000
								});
							}
							// console.log(this.sendCardnumber);
							uni.stopPullDownRefresh();
						}
					});
				} catch (e) {
					console.log(e.message);
				}
			}
		}
	};
</script>

<style  lang="scss">
	.base-content{
		width: 100%;
		min-width: 750px;
		color: rgba(31,31,31,1);
		font-size:30px;
		background: #F3F3F3;
	}
	.base-box{
		width: 100%;
		background: #fff;
		border-top:1px solid #F3F3F3; 
		height: 130px;
		line-height: 130px;
		padding: 0 20px;
		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		.base-box-number{
			display: flex;
			flex-direction: row;
			justify-content: flex-end;
			font-weight:bold;
			color:rgba(0,150,255,1);
			text{
				color: rgba(31,31,31,1);
				font-weight:500;
				margin-left: 10px;
			}
		}
	}
</style>
